﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using BackupObjects.Taging;

namespace Backup.Services.Entities
{
    /// <summary>
    /// Mapping Tag entity for communication.
    /// </summary>
    [DataContract]
    public class TagEntity
    {
        public TagEntity()
        {
            Id = Guid.NewGuid();            
        }

        /// <summary>
        /// Gets or sets the id of tag.
        /// </summary>
        [DataMember]
        public Guid Id { get; set; }

        /// <summary>
        /// Gets or sets the name of the tag.
        /// </summary>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the id of parent tag.
        /// </summary>
        [DataMember]
        public Guid? Parent { get; set; }

        public override string ToString()
        {
            return Name;
        }

        public static implicit operator Guid(TagEntity tag)
        {
            return tag.Id;
        }

        public static implicit operator TagEntity(Tag tag)
        {
            return tag == null
                       ? null
                       : new TagEntity()
                             {
                                 Id = tag.Id,
                                 Name = tag.Name,
                                 Parent = tag.Parent
                             };
        }

        public static implicit operator Tag(TagEntity tag)
        {
            return tag == null
                       ? null
                       : new Tag()
                             {
                                 Id = tag.Id,
                                 Name = tag.Name,
                                 Parent = tag.Parent
                             };
        }
    }
}
